package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsEnergyEquipment;
import com.econ.powercloud.ems.dal.mapper.EmsEnergyEquipmentMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 储能装置 dao层
 * @Date : 2021/7/28 14:54
 * @Modified by : zjf
 */
@Repository
public class EmsEnergyEquipmentDAO extends ServiceImpl<EmsEnergyEquipmentMapper, EmsEnergyEquipment> {

    /**
     * 通过多个公司获取这些公司的全部的储能装置
     */
    public List<EmsEnergyEquipment> selectByStationIds(List<String> stationIds){
        LambdaQueryWrapper<EmsEnergyEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(EmsEnergyEquipment::getEnergyStationId,stationIds);
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }

    public Page<EmsEnergyEquipment> selectListByStationId(String energyStationId, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<EmsEnergyEquipment> emsEnergyEquipmentLambdaQueryWrapper = Wrappers.lambdaQuery();
        emsEnergyEquipmentLambdaQueryWrapper.eq(!StringUtils.isNullOrEmpty(energyStationId), EmsEnergyEquipment::getEnergyStationId, energyStationId);
        Page<EmsEnergyEquipment> emsEnergyEquipmentPage = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(emsEnergyEquipmentPage, emsEnergyEquipmentLambdaQueryWrapper);
    }

    /**
     * 查询全部数据
     */
    public List<EmsEnergyEquipment> selectAll(){
        LambdaQueryWrapper<EmsEnergyEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }

    /**
     * 获取一个储能装置的信息
     */
    public EmsEnergyEquipment selectByStationIdAndEquipmentId(String energyStationId, String energyEquipmentId){
        LambdaQueryWrapper<EmsEnergyEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(EmsEnergyEquipment::getEnergyStationId,energyStationId);
        lambdaQueryWrapper.eq(EmsEnergyEquipment::getEnergyEquipmentId,energyEquipmentId);
        return this.baseMapper.selectOne(lambdaQueryWrapper);
    }

    public int deleteByStationId(String stationId){
        LambdaQueryWrapper<EmsEnergyEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(EmsEnergyEquipment::getEnergyStationId,stationId);
        return this.baseMapper.delete(lambdaQueryWrapper);
    }
}
